package java04;

public class Exception04 {
    public static void printAge(int age) throws Exception{
        if(age <= 0){
            //对业务逻辑判断，当输入的的年龄为负数时抛出异常
            throw new Exception("输入的年龄有误，必须是正数！");
        }else{
            System.out.println("此人年龄为：" + age);
        }
    }
    public static void main(String[] args){
        int age = -1;
        try{
            printAge(age);
        }catch (Exception e){
            System.out.println("捕获的异常信息为：" + e.getMessage());
        }
    }
}
